Imports System.IO
Imports System.Text

Public Class UpgradeLog

    Private Const LogFile As String = "upgrade.log"

    Private Shared _log As StreamWriter

    Private Const HeaderSeparator As String = "--------------------------------------------------"
    Private Const HeaderText As String = "Upgrade Started {0}"

    Public Shared Sub OpenLog()

        Dim log As FileStream
        Dim logFilePath As String = My.Settings.DataDirectory & LogFile

        If Not File.Exists(logFilePath) Then
            log = File.Create(logFilePath)
        Else
            log = New FileStream(logFilePath, FileMode.Append)
        End If

        _log = New StreamWriter(log)

        WriteUpgradeHeader()

    End Sub

    Public Shared Sub CloseLog()

        If Not _log Is Nothing Then
            _log.WriteLine()
            _log.WriteLine()

            _log.Flush()
            _log.Close()
        End If

    End Sub

    Public Shared Sub WriteEntry(ByVal message As String)
        _log.WriteLine(message)
    End Sub

    Private Shared Sub WriteUpgradeHeader()

        _log.WriteLine(HeaderSeparator)
        _log.WriteLine()
        _log.WriteLine(String.Format(HeaderText, Now))
        _log.WriteLine()
        _log.WriteLine(HeaderSeparator)
        _log.WriteLine()

    End Sub

    Private Sub New()

    End Sub

End Class
